<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('绩效人员列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="dept-form">
                <div class="select-list">
                    <ul>
                        <li>
                            岗位名称：<input type="text" name="jobName" id="jobName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="downLoadTemplate()">
                <i class="fa fa-download"></i> 下载绩效模板
            </a>
            <a class="btn btn-success" onclick="addJob()">
                <i class="fa fa-plus"></i> 新增通用岗位
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">

    var prefix = ctx + "acvJobManage"

    $(function () {

        var options = {
            url: prefix + '/selectCurrencyJobList',
            uniqueId: "id",
            id: 'bootstrap-table',
            importUrl: prefix + "/importTemplateFile",
            modalName: "通用岗位",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: true,
            detailView: true,
            detailFormatter: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [
                {
                    field: 'jobName',
                    title: '通用岗位名称'
                },
                {
                    title: '类型',
                    formatter: function (value, item, index) {
                        return '<span class="label label-success">通用岗位</span>';
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + '" onclick="openUpdateTemplate(\'' + row.jobId + '\')" href="javascript:void(0)"><i class="fa fa-edit"></i>更新</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + '" onclick="downloadTemplateByJobId(\'' + row.jobId + '\')" href="javascript:void(0)"><i class="fa fa-download"></i>下载</a> ');
                        return actions.join('');
                    }
                }
            ]
        }
        $.table.init(options);
    });

    initChildTable = function (index, row, $detail) {
        var childTable = $detail.html('<table></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/selectCurrencyTemplateList",
            queryParams: {jobId: row.jobId},
            method: 'post',
            uniqueId: row.id,
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [
                {
                    field: 'assessment_index',
                    title: '考核指标'
                },
                {
                    field: 'describe',
                    title: '考核描述'
                },
                {
                    field: 'goal',
                    title: '达成目标'
                },
                {
                    field: 'standard',
                    title: '评分标准'
                },
                {
                    field: 'distribution',
                    title: '指标配分'
                }
            ]
        });
    }

    function downLoadTemplate() {
        $.operate.exportData("acvTemplateManage/downloadTemplate", "考核项模板");
    }

    function openUpdateTemplate(jobId) {
        $.modal.confirm("更新通用模板将会同步更新使用该通用岗位的所有岗位模板，确定更新吗?", function() {
            $.table.importExcelCustom("openUpdateTemplate", "更新通用模板", prefix + "/updateTemplate?jobId=" + jobId, 'file1');
        });
    }

    function downloadTemplateByJobId(jobId){
        $.operate.exportData("acvJobManage/downloadTemplateByJobId?jobId=" + jobId, "通用模板");
    }

    function addJob(){
        var url = ctx + "acvJobManage/addJob";
        var title = '新增通用岗位';
        $.modal.open(title, url, 500, 500);
    }
</script>

<script id="openUpdateTemplate" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file1" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</body>
</html>